# Maintainer: Renato Silva <br.renatosilva@gmail.com>
# Contributor: David Macek <david.macek.0@gmail.com>

_realname=silc-toolkit
pkgbase=mingw-w64-${_realname}
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname})
pkgver=1.1.12
pkgrel=3
url="http://silcnet.org/"
pkgdesc="Secure Internet Live Conferencing (mingw-w64)"
license=('GPL2' 'BSD')
arch=('any')
depends=(${MINGW_PACKAGE_PREFIX}-libsystre)
makedepends=(${MINGW_PACKAGE_PREFIX}-gcc)
options=('staticlibs' '!emptydirs')
source=(#https://github.com/silc/silc/archive/${_realname//-/.}.${pkgver}.tar.gz
        "https://downloads.sourceforge.net/project/silc/silc/toolkit/sources/silc-toolkit-${pkgver}.tar.gz"
        001-remove-outdated-mno-cygwin-gcc-option.patch
        002-fixes-for-64-bit.patch
        003-fix-references-to-slash-usr.patch
        004-link-with-regex-and-silc.patch
        005-fix-some-compiler-check.patch
        006-disable-dllimport-for-silcske.patch)
sha256sums=('7e0c3f73471b54ba55f5ac42979ed0d642afd8ae18a973c16b2a667c6c72db56'
            '0d415556adeba40b1fc6b6660e612f8c96507c07ab025916acb726932e144aa4'
            '68f96d3d20c7cca3b8be7480ff632947c8aed5f8dd9fb731978f61a41ed0ff70'
            '652362d5f316c4e7030d574b59a6199fbb44aed398229aed8b91b54cfa7fe696'
            'cf0cd49f2d471cd71510a1959d4dcdd8f33b3a7c4ab70820a3ef44972b2ce931'
            '184c10c6e066c61f8bdcee84be7aa28a7ab906353fe082b6328faf8fbfb7799b'
            'adc6f10cbaf6e48a6fa03d4fd65c604ede480382ea0ce7cad5ff44b3ae87b3be')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/001-remove-outdated-mno-cygwin-gcc-option.patch
  patch -p1 -i "${srcdir}"/002-fixes-for-64-bit.patch
  patch -p1 -i "${srcdir}"/003-fix-references-to-slash-usr.patch
  patch -p1 -i "${srcdir}"/004-link-with-regex-and-silc.patch
  patch -p1 -i "${srcdir}"/005-fix-some-compiler-check.patch
  patch -p1 -i "${srcdir}"/006-disable-dllimport-for-silcske.patch
  autoreconf -sif
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./configure \
      --prefix=${MINGW_PREFIX} \
      --with-simdir=${MINGW_PREFIX}/lib/silc/modules \
      --with-win32

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  # Licenses
  install -Dm644 COPYING  ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
  install -Dm644 GPL      ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/GPL
  install -Dm644 BSD      ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/BSD
}
